package com.guanjian.netty.learning.bio;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * created by guanjian on 2019/10/9 9:44
 */
public class BIOServer {
    public static void main(String[] args) throws IOException {
        int port = 8080;
        if (null != args && args.length > 0){
            try{
                port = Integer.valueOf(args[0]);
            }catch (Exception e){
                //采用默认值
            }
        }
        ServerSocket server = null;
        Socket socket = null;
        try {
            server = new ServerSocket(port);
            while (true){
                socket = server.accept();
                new Thread(new BIOServerHandler(socket)).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (null != server){
                server.close();
            }
        }
    }
}
